﻿using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Acme.BookStore2.Localization;
using Microsoft.Extensions.Localization;
using Volo.Abp;
using Volo.Abp.BlobStoring;
using Volo.Abp.Domain.Services;

namespace Acme.BookStore2
{
    public class BlobManager : DomainService
    {
        private readonly IBlobContainer<VehicleBlobContainer> _vehicleBlobContainer;

        public BlobManager(IBlobContainer<VehicleBlobContainer> vehicleBlobContainer)
        {
            _vehicleBlobContainer = vehicleBlobContainer;
        }

        public async Task SaveAsync(string blobContainerName, string blobName, byte[] bytes)
        {
            switch (blobContainerName)
            {
                case BlobContainerNameConsts.Vehicle:
                    await _vehicleBlobContainer.SaveAsync(blobName, bytes);
                    break;
            }
        }
        
        public async Task<byte[]> GetAllBytesOrNullAsync(string blobContainerName, string blobName)
        {
            switch (blobContainerName)
            {
                case BlobContainerNameConsts.Vehicle:
                    return await _vehicleBlobContainer.GetAllBytesOrNullAsync(blobName);
            }
            return default;
        }
    }
}